package jcpcotizaciones.vista;

import java.sql.SQLException;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import jcpcotizaciones.Control.*;
import jcpcotizaciones.Modelo.*;
import jcpcotizaciones.vista.*;

public class FormatoSimple extends javax.swing.JFrame {


    public FormatoSimple() {
        initComponents();
        listarCortePapel();
        listarTipoMaquina();
        listarTipoPapel();
    }

    DefaultComboBoxModel defaultcombocortepapel = new DefaultComboBoxModel();
    DefaultComboBoxModel defaultcombotipopapel = new DefaultComboBoxModel();
    DefaultComboBoxModel defaultcombotipomaquina = new DefaultComboBoxModel();
    double vrtotal;
    double vrunitario;
    private vistaCotizacion vc;
    private vistaOtros vo;
    


    double cantPliegos;
    double vrpapel;
    int millares;
    double impresion;
    double planchas;
    double valor;
    double tirospapel;




    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        piso_formato = new jcMousePanel.jcMousePanel();
        jLabel21 = new javax.swing.JLabel();
        tx_cantidad = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        tx_descripcion = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        cb_cortePapel = new javax.swing.JComboBox(defaultcombocortepapel);
        jLabel11 = new javax.swing.JLabel();
        cb_tipoPapel = new javax.swing.JComboBox(defaultcombotipopapel);
        jLabel12 = new javax.swing.JLabel();
        cb_tipoMaquina = new javax.swing.JComboBox(defaultcombotipomaquina);
        jcMousePanel1 = new jcMousePanel.jcMousePanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        sp_tiro = new javax.swing.JSpinner();
        sp_retiro = new javax.swing.JSpinner();
        tx_num_item = new javax.swing.JLabel();
        tx_arte = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        tx_tamano = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        tx_transporte = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        sp_montaje = new javax.swing.JSpinner();
        jLabel8 = new javax.swing.JLabel();
        tx_refile = new javax.swing.JTextField();
        botonera = new jcMousePanel.jcMousePanel();
        bt_agregar = new javax.swing.JButton();
        bt_cancelar = new javax.swing.JButton();
        bt_cerrar = new javax.swing.JButton();
        tx_ganancia = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        bt_vistaprevia = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        areadetexto = new javax.swing.JTextArea();
        tx_vrtotal = new javax.swing.JTextField();
        tx_vrunitario = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        tx_otros = new javax.swing.JTextField();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(jcpcotizaciones.JCPCOTIZACIONESApp.class).getContext().getResourceMap(FormatoSimple.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        piso_formato.setIcon(resourceMap.getIcon("piso_formato.icon")); // NOI18N
        piso_formato.setName("piso_formato"); // NOI18N

        jLabel21.setText(resourceMap.getString("jLabel21.text")); // NOI18N
        jLabel21.setName("jLabel21"); // NOI18N

        tx_cantidad.setName("tx_cantidad"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        tx_descripcion.setName("tx_descripcion"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        cb_cortePapel.setMaximumRowCount(5);
        cb_cortePapel.setName("cb_cortePapel"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        cb_tipoPapel.setMaximumRowCount(5);
        cb_tipoPapel.setName("cb_tipoPapel"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        cb_tipoMaquina.setMaximumRowCount(5);
        cb_tipoMaquina.setName("cb_tipoMaquina"); // NOI18N

        jcMousePanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jcMousePanel1.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jcMousePanel1.border.titleFont"), resourceMap.getColor("jcMousePanel1.border.titleColor"))); // NOI18N
        jcMousePanel1.setIcon(resourceMap.getIcon("jcMousePanel1.icon")); // NOI18N
        jcMousePanel1.setName("jcMousePanel1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        sp_tiro.setModel(new javax.swing.SpinnerNumberModel(1, 0, 9, 1));
        sp_tiro.setName("sp_tiro"); // NOI18N

        sp_retiro.setModel(new javax.swing.SpinnerNumberModel(0, 0, 9, 1));
        sp_retiro.setName("sp_retiro"); // NOI18N

        javax.swing.GroupLayout jcMousePanel1Layout = new javax.swing.GroupLayout(jcMousePanel1);
        jcMousePanel1.setLayout(jcMousePanel1Layout);
        jcMousePanel1Layout.setHorizontalGroup(
            jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel1Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 53, Short.MAX_VALUE)
                .addComponent(jLabel2))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jcMousePanel1Layout.createSequentialGroup()
                .addComponent(sp_tiro, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addComponent(sp_retiro, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jcMousePanel1Layout.setVerticalGroup(
            jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel1Layout.createSequentialGroup()
                .addGroup(jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(sp_tiro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(sp_retiro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        tx_num_item.setFont(resourceMap.getFont("tx_num_item.font")); // NOI18N
        tx_num_item.setForeground(resourceMap.getColor("tx_num_item.foreground")); // NOI18N
        tx_num_item.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        tx_num_item.setText(resourceMap.getString("tx_num_item.text")); // NOI18N
        tx_num_item.setName("tx_num_item"); // NOI18N

        tx_arte.setText(resourceMap.getString("tx_arte.text")); // NOI18N
        tx_arte.setName("tx_arte"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        tx_tamano.setText(resourceMap.getString("tx_tamano.text")); // NOI18N
        tx_tamano.setName("tx_tamano"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        tx_transporte.setText(resourceMap.getString("tx_transporte.text")); // NOI18N
        tx_transporte.setName("tx_transporte"); // NOI18N

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tx_cantidad, org.jdesktop.beansbinding.ObjectProperty.create(), tx_transporte, org.jdesktop.beansbinding.BeanProperty.create("nextFocusableComponent"));
        bindingGroup.addBinding(binding);

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        sp_montaje.setModel(new javax.swing.SpinnerNumberModel(1, 1, 500, 1));
        sp_montaje.setName("sp_montaje"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        tx_refile.setText(resourceMap.getString("tx_refile.text")); // NOI18N
        tx_refile.setName("tx_refile"); // NOI18N

        botonera.setIcon(resourceMap.getIcon("botonera.icon")); // NOI18N
        botonera.setName("botonera"); // NOI18N

        bt_agregar.setText(resourceMap.getString("bt_agregar.text")); // NOI18N
        bt_agregar.setToolTipText(resourceMap.getString("bt_agregar.toolTipText")); // NOI18N
        bt_agregar.setName("bt_agregar"); // NOI18N
        bt_agregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_agregarActionPerformed(evt);
            }
        });

        bt_cancelar.setText(resourceMap.getString("bt_cancelar.text")); // NOI18N
        bt_cancelar.setToolTipText(resourceMap.getString("bt_cancelar.toolTipText")); // NOI18N
        bt_cancelar.setName("bt_cancelar"); // NOI18N
        bt_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_cancelarActionPerformed(evt);
            }
        });

        bt_cerrar.setText(resourceMap.getString("bt_cerrar.text")); // NOI18N
        bt_cerrar.setName("bt_cerrar"); // NOI18N
        bt_cerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_cerrarActionPerformed(evt);
            }
        });

        tx_ganancia.setText(resourceMap.getString("tx_ganancia.text")); // NOI18N
        tx_ganancia.setName("tx_ganancia"); // NOI18N

        jLabel22.setFont(resourceMap.getFont("jLabel22.font")); // NOI18N
        jLabel22.setText(resourceMap.getString("jLabel22.text")); // NOI18N
        jLabel22.setName("jLabel22"); // NOI18N

        bt_vistaprevia.setText(resourceMap.getString("bt_vistaprevia.text")); // NOI18N
        bt_vistaprevia.setName("bt_vistaprevia"); // NOI18N
        bt_vistaprevia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_vistapreviaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout botoneraLayout = new javax.swing.GroupLayout(botonera);
        botonera.setLayout(botoneraLayout);
        botoneraLayout.setHorizontalGroup(
            botoneraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, botoneraLayout.createSequentialGroup()
                .addContainerGap(60, Short.MAX_VALUE)
                .addComponent(jLabel22)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tx_ganancia, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_vistaprevia)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bt_agregar, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_cancelar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_cerrar)
                .addContainerGap())
        );
        botoneraLayout.setVerticalGroup(
            botoneraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, botoneraLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(botoneraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_cerrar)
                    .addComponent(bt_agregar)
                    .addComponent(bt_cancelar)
                    .addComponent(bt_vistaprevia)
                    .addComponent(jLabel22)
                    .addComponent(tx_ganancia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        areadetexto.setColumns(20);
        areadetexto.setFont(resourceMap.getFont("areadetexto.font")); // NOI18N
        areadetexto.setRows(5);
        areadetexto.setText(resourceMap.getString("areadetexto.text")); // NOI18N
        areadetexto.setName("areadetexto"); // NOI18N
        jScrollPane1.setViewportView(areadetexto);

        tx_vrtotal.setText(resourceMap.getString("tx_vrtotal.text")); // NOI18N
        tx_vrtotal.setEnabled(false);
        tx_vrtotal.setName("tx_vrtotal"); // NOI18N

        tx_vrunitario.setText(resourceMap.getString("tx_vrunitario.text")); // NOI18N
        tx_vrunitario.setEnabled(false);
        tx_vrunitario.setName("tx_vrunitario"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        tx_otros.setText(resourceMap.getString("tx_otros.text")); // NOI18N
        tx_otros.setEnabled(false);
        tx_otros.setName("tx_otros"); // NOI18N

        javax.swing.GroupLayout piso_formatoLayout = new javax.swing.GroupLayout(piso_formato);
        piso_formato.setLayout(piso_formatoLayout);
        piso_formatoLayout.setHorizontalGroup(
            piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(piso_formatoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tx_num_item)
                    .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, piso_formatoLayout.createSequentialGroup()
                            .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jcMousePanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(tx_arte, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(tx_cantidad, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(tx_tamano, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(tx_descripcion, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel21, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING))
                                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel6)
                                .addGroup(piso_formatoLayout.createSequentialGroup()
                                    .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(tx_otros)
                                        .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel11)
                                            .addComponent(jLabel8)
                                            .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                .addGroup(piso_formatoLayout.createSequentialGroup()
                                                    .addComponent(jLabel7)
                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                    .addComponent(sp_montaje, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addComponent(cb_tipoMaquina, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(cb_tipoPapel, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(cb_cortePapel, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(tx_refile, javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(tx_transporte, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE))
                                            .addComponent(jLabel10)
                                            .addComponent(jLabel12)))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(piso_formatoLayout.createSequentialGroup()
                                            .addComponent(jLabel13)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(tx_vrunitario, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jLabel14)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(tx_vrtotal, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addComponent(botonera, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        piso_formatoLayout.setVerticalGroup(
            piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(piso_formatoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tx_num_item)
                .addGap(18, 18, 18)
                .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(piso_formatoLayout.createSequentialGroup()
                        .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tx_arte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tx_transporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel21)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tx_cantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tx_refile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(jLabel10))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tx_descripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cb_cortePapel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jLabel11))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tx_tamano, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cb_tipoPapel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                        .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(piso_formatoLayout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addGap(4, 4, 4)
                                .addComponent(cb_tipoMaquina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                                .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel7)
                                    .addComponent(sp_montaje, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jcMousePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(piso_formatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel13)
                        .addComponent(tx_vrunitario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel14)
                        .addComponent(tx_otros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(tx_vrtotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonera, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(piso_formato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(piso_formato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bt_agregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_agregarActionPerformed
        try {
            if (ControlCotizacion.BuscarCotizacion(vc.tx_numero.getText()) == null) {
                vc.agregarCotizacion();
                valoresItem();
                agregarItem();
                vc.guardarCotizacion();
            } else {
                valoresItem();
                agregarItem();
                vc.guardarCotizacion();
            }
            limpiartodo();
        } catch (SQLException ex) {
            Logger.getLogger(FormatoSimple.class.getName()).log(Level.SEVERE, null, ex);
        }

      
}//GEN-LAST:event_bt_agregarActionPerformed

    private void bt_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_cancelarActionPerformed
        limpiartodo();
}//GEN-LAST:event_bt_cancelarActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        
        

    }//GEN-LAST:event_jButton3ActionPerformed

    private void bt_cerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_cerrarActionPerformed
        vc.jDial_formatosimple.setVisible(false);
    }//GEN-LAST:event_bt_cerrarActionPerformed

    private void bt_vistapreviaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_vistapreviaActionPerformed
        valoresItem ();
        imprimir();
    }//GEN-LAST:event_bt_vistapreviaActionPerformed


    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FormatoSimple().setVisible(true);
            }
        });
    }

     public void listarTipoMaquina(){
       try {
            TipoDeMaquina tim = new TipoDeMaquina();
            defaultcombotipomaquina.removeAllElements();
            defaultcombotipomaquina.addElement("Seleccione Maquina... ");

            ControlTipoDeMaquina.listarTipoDeMaquina();
            Iterator it = ControlTipoDeMaquina.getTipoMaquina().iterator();
            while (it.hasNext()) {
                tim = (TipoDeMaquina) it.next();
                defaultcombotipomaquina.addElement(tim.getCodigoMaquina() + " - " + tim.getNombre());
            }
            cb_tipoMaquina.setModel(defaultcombotipomaquina);
        } catch (SQLException ex) {
            Logger.getLogger(vistaCotizacion.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaCotizacion.class.getName()).log(Level.SEVERE, null, ex);
        }
   }

    public void listarTipoPapel(){
       
       try {
            TipoPapel tip = new TipoPapel();
            defaultcombotipopapel.removeAllElements();
            defaultcombotipopapel.addElement(" Seleccione Papel...");
            ControlTipoPapel.listarTipoPapel();
            Iterator it = ControlTipoPapel.getTipoPapel().iterator();
            while (it.hasNext()) {
                tip = (TipoPapel) it.next();
                defaultcombotipopapel.addElement(tip.getCod_papel() + " - " + tip.getNombre());
            }
            cb_tipoPapel.setModel(defaultcombotipopapel);
        } catch (SQLException ex) {
            Logger.getLogger(vistaCotizacion.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaCotizacion.class.getName()).log(Level.SEVERE, null, ex);
        }
   }

    public void imprimir(){
        String mensaje = tx_cantidad.getText()+" "+ tx_descripcion.getText()+ " tamaño " + tx_tamano.getText()+" en \npapel "
                + tp.getNombre() + " impresos a " + sp_tiro.getValue().toString()+"x"+sp_retiro.getValue().toString()+" tintas.\n\n"+
                "MILLARES: "+ Double.toString(millares);
        areadetexto.setText(mensaje);
    }

    public void listarCortePapel(){
       try {
            CortePapel cop = new CortePapel();
            defaultcombocortepapel.removeAllElements();
            defaultcombocortepapel.addElement(" Seleccione Corte de Papel...");
            ControlCortePapel.listarCortePapel();
            Iterator it = ControlCortePapel.getCortePapel().iterator();
            while (it.hasNext()) {
                cop = (CortePapel) it.next();
                defaultcombocortepapel.addElement(cop.getCodigoCorte() + " - " + cop.getNombre());
            }
            cb_cortePapel.setModel(defaultcombocortepapel);
        } catch (SQLException ex) {
            Logger.getLogger(vistaCotizacion.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaCotizacion.class.getName()).log(Level.SEVERE, null, ex);
        }
   }
  public void limpiartodo(){
      tx_cantidad.setText("");
      tx_descripcion.setText("");
      tx_arte.setText("");
      tx_refile.setText("");
      tx_tamano.setText("");
      tx_transporte.setText("");
      tx_ganancia.setText("80");
      sp_tiro.setValue(1);
      sp_retiro.setValue(0);
      sp_montaje.setValue(1);
      cb_cortePapel.setSelectedIndex(0);
      cb_tipoPapel.setSelectedIndex(0);
      cb_tipoMaquina.setSelectedIndex(0);
    }
        TipoPapel tp;
        CortePapel cp;
        TipoDeMaquina tm;

   public void valoresItem (){

        if (tx_cantidad.getText().trim().equals("") || tx_descripcion.getText().trim().equalsIgnoreCase("")||cb_cortePapel.getSelectedIndex()==0 || cb_tipoPapel.getSelectedIndex()==0 || cb_tipoMaquina.getSelectedIndex()==0 || tx_arte.getText().trim().equalsIgnoreCase("") || tx_refile.getText().trim().equalsIgnoreCase("") || tx_tamano.getText().trim().equalsIgnoreCase("") || tx_transporte.getText().trim().equalsIgnoreCase("")){
                    JOptionPane.showMessageDialog(null,"Por favor Llene todos los campos");
                }else{
        try {
            int cantidad = Integer.parseInt(tx_cantidad.getText());
            int canTintas = Integer.parseInt(sp_tiro.getValue().toString()) + Integer.parseInt(sp_retiro.getValue().toString());
            int cantMontaje = cantidad / Integer.parseInt(sp_montaje.getValue().toString());

            StringTokenizer st = new StringTokenizer(cb_cortePapel.getSelectedItem().toString(),"-");
            String codcorte = st.nextToken();
            cp = ControlCortePapel.BuscarCortePapel(codcorte.trim());

            StringTokenizer st2 = new StringTokenizer(cb_tipoPapel.getSelectedItem().toString(),"-");
            String codtipo = st2.nextToken();
            tp = ControlTipoPapel.BuscarTipoPapel(codtipo.trim());

            

            StringTokenizer st4 = new StringTokenizer(cb_tipoMaquina.getSelectedItem().toString(),"-");
            String codmaquina = st4.nextToken();
            tm = ControlTipoDeMaquina.BuscarTipoDeMaquina(codmaquina.trim());

             cantPliegos = cantMontaje / cp.getCantidadPliego();
             vrpapel = cantPliegos * tp.getValor();
             tirospapel = cantMontaje/1000;
             double tirospapelMod = cantMontaje%1000;

             if (tirospapel < 1){
                 tirospapel = 1;
             }else{

                 if (tirospapelMod > 100){
                     tirospapel +=1;
                 }
             }
             

            millares = (int)tirospapel * canTintas ;
           
            impresion = millares * tm.getValorMillar();
            planchas = canTintas* tm.getValorPlancha();
            valor = vrpapel + impresion + planchas;
            vrtotal = valor + ((valor * Integer.parseInt(tx_ganancia.getText()))/100);
            vrunitario = vrtotal / cantidad;
            System.out.print("cantidad: " + cantidad + "\nTintas: " + canTintas +"\nCant Montaje: " + cantMontaje +"\nPliegos: " + cantPliegos +"\nValor Papel: " + vrpapel +"\ntiros pepel: " + tirospapel
                    +"\nTiros Mod: " + tirospapelMod +"\nMillares: " + millares +"\nimpresion: " + impresion +"\nPLanchas: " + planchas +"\nGastos: " + valor +"\nValor Trabajo: " + vrtotal +"\nValor Unitario: " + vrunitario);
        } catch (SQLException ex) {
            Logger.getLogger(vistaCotizacion.class.getName()).log(Level.SEVERE, null, ex);
        }
                }

    }


public void agregarItem(){

try {
                Item i = new Item();
                    i.setNumero(tx_num_item.getText());
                    i.setCantidad(Integer.parseInt(tx_cantidad.getText()));
                    i.setDescripcion(tx_descripcion.getText());
                    i.setCotizacion(ControlCotizacion.BuscarCotizacion(vc.tx_numero.getText()));
                    i.setArte(Double.parseDouble(tx_arte.getText()));
                    i.setMontaje(Integer.parseInt(sp_montaje.getValue().toString()));
                    i.setRefile(Double.parseDouble(tx_refile.getText()));
                    i.setOtro(null);
                    i.setTamanoFinal(tx_tamano.getText());
                    i.setTransporte(Double.parseDouble(tx_transporte.getText()));
                    i.setTiro(Integer.parseInt(sp_tiro.getValue().toString()));
                    i.setRetiro(Integer.parseInt(sp_retiro.getValue().toString()));
                    StringTokenizer st = new StringTokenizer(cb_cortePapel.getSelectedItem().toString(),"-");
                    String cod = st.nextToken();
                    i.setCortepapel(ControlCortePapel.BuscarCortePapel(cod.trim()));

                    StringTokenizer st1 = new StringTokenizer(cb_tipoPapel.getSelectedItem().toString(),"-");
                    String cod1 = st1.nextToken();
                    i.setTipopapel(ControlTipoPapel.BuscarTipoPapel(cod1.trim()));


                    StringTokenizer st2 = new StringTokenizer(cb_tipoMaquina.getSelectedItem().toString(),"-");
                    String cod2 = st2.nextToken();
                    i.setMaquina(ControlTipoDeMaquina.BuscarTipoDeMaquina(cod2.trim()));


                    i.setTiro(Integer.parseInt(sp_tiro.getValue().toString()));
                    i.setRetiro(Integer.parseInt(sp_retiro.getValue().toString()));

                    i.setValorunitario(vrunitario);
                    i.setValortotal(vrtotal);

                    ControlItem.agregarItem(i);
                    vc.listarItem();
            
        } catch (SQLException ex) {
            Logger.getLogger(vistaCotizacion.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaCotizacion.class.getName()).log(Level.SEVERE, null, ex);
        }
}




    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea areadetexto;
    private jcMousePanel.jcMousePanel botonera;
    private javax.swing.JButton bt_agregar;
    private javax.swing.JButton bt_cancelar;
    private javax.swing.JButton bt_cerrar;
    private javax.swing.JButton bt_vistaprevia;
    private javax.swing.JComboBox cb_cortePapel;
    private javax.swing.JComboBox cb_tipoMaquina;
    private javax.swing.JComboBox cb_tipoPapel;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private jcMousePanel.jcMousePanel jcMousePanel1;
    public static jcMousePanel.jcMousePanel piso_formato;
    private javax.swing.JSpinner sp_montaje;
    private javax.swing.JSpinner sp_retiro;
    private javax.swing.JSpinner sp_tiro;
    private javax.swing.JTextField tx_arte;
    private javax.swing.JTextField tx_cantidad;
    private javax.swing.JTextField tx_descripcion;
    private javax.swing.JTextField tx_ganancia;
    public javax.swing.JLabel tx_num_item;
    private javax.swing.JTextField tx_otros;
    private javax.swing.JTextField tx_refile;
    private javax.swing.JTextField tx_tamano;
    private javax.swing.JTextField tx_transporte;
    private javax.swing.JTextField tx_vrtotal;
    private javax.swing.JTextField tx_vrunitario;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the vc
     */
    public vistaCotizacion getVc() {
        return vc;
    }

    /**
     * @param vc the vc to set
     */
    public void setVc(vistaCotizacion vc) {
        this.vc = vc;
    }



}
